/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoo.psdk.remote;

import android.content.Context;
import android.text.TextUtils;
import com.qihoo.psdk.util.a;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Date;
import java.util.Random;

public class e {
    private static boolean a = true;
    private static boolean b = true;
    private static long c = 0L;
    private static boolean d = false;
    private static long e = 180000L;

    protected static void a(Context paramContext) {
        com.qihoo.psdk.util.h.a("QInit", "Init session...");
        new f(paramContext).start();
        b(paramContext);
        c(paramContext);
    }

    private static void b(Context paramContext) {
        if (!(a))
            return;
        com.qihoo.psdk.util.h.a("QInit", "Check session...");
        a = false;
        new g(paramContext).start();
    }

    private static void c(Context paramContext) {
        if (!(b))
            return;
        b = false;
        new h(paramContext).start();
    }

    protected static void a(Context paramContext, boolean paramBoolean) {
        if (a.e(paramContext)) {
            if (m.c())
                return;
            long l = new Date().getTime();
            if (l - c < 15000L)
                return;
            c = l;
            if (!(d)) {
                com.qihoo.psdk.util.h.a("QInit", "Get ip configure...");
                d(paramContext);
            }
            else if (paramBoolean) {
                com.qihoo.psdk.util.h.a("QInit", "Update ip configure...");
                d(paramContext);
            }
            if (!(d))
                return;
            m.a(paramContext);
        }
        else {
            m.a();
        }
    }

    private static void d(Context paramContext) {
        Object localObject1 = null;
        Object localObject2 = null;
        Object localObject3 = null;
        try {
            String str1 = com.qihoo.psdk.e.a(paramContext, n.a);
            com.qihoo.psdk.util.h.a("QInit", "url: " + n.a + ", response: " + str1);
            if (TextUtils.isEmpty(str1))
                break label242;
            String[] arrayOfString = str1.split("\n");
            if (arrayOfString.length <= 0)
                break label242;
            int i = new Random().nextInt();
            if (i < 0)
                i = -i;
            int j = i % arrayOfString.length;
            String str2 = arrayOfString[j];
            if ((TextUtils.isEmpty(str2)) || (str2.equals("\n")))
                break label242;
            arrayOfString = str2.split(":");
            if (2 == arrayOfString.length) {
                n.a(arrayOfString[0]);
                n.a(Integer.parseInt(arrayOfString[1]));
                d = true;
                com.qihoo.psdk.util.h.a("QInit", "seed: " + i + ", index: " + j);
                com.qihoo.psdk.util.h.a("QInit", "Push server: " + n.b());
                label242: com.qihoo.psdk.util.h.a("QInit", "Push port: " + n.c());
            }
        } catch (Exception localException1) {
            com.qihoo.psdk.util.h.a("QInit", localException1);
        } finally {
            try {
                if (localObject1 != null) {
                    localObject1.close();
                    localObject1 = null;
                }
                if (localObject2 != null) {
                    localObject2.close();
                    localObject2 = null;
                }
                if (localObject3 != null) {
                    localObject3.close();
                    localObject3 = null;
                }
            } catch (Exception localException3) {
                com.qihoo.psdk.util.h.a("QInit", localException3);
            }
        }
    }

    protected static void a(long paramLong) {
        e = paramLong;
    }

    protected static long a() {
        return (e / 60000L);
    }
}